# 方法一
class Solution:
    def isPowerOfTwo(self, n: int) -> bool:
        if n <= 0:# n负数一定不为整数
            return False
        if n == 1:
            return True
        while n > 1:
            if n % 2 != 0:
                return False
            n = n / 2
        return True


#方法二 位运算
class Solution:
    def isPowerOfTwo(self, n: int) -> bool:
        return n > 0 and n & (n - 1) == 0